<?php
include_once('_lib/class.quickskin.php');
include_once('_lib/config.php');
include_once('_lib/class.base.php');

$usr = $_POST["name"];
$pwd = $_POST["password"];
echo $usr;
echo $pwd;
if(empty($usr)&&empty($pwd)){
	$key = $_GET["key"];
	if($key!="warabi"){
		echo "<h2>Sorry , you have no permission.</h2>";
		exit;
	}

	$newpage = new QuickSkin('tpl/index.html');
	$newpage -> assign('title' , "Warabi Admin Login");
	$newpage -> output();
}
else{
	global $wbTableHash;
	$loginBase = new base("admin");
	$obj = array(
				array("type" => ET_SELECT),
				array("*"),
				array("name"=>$usr , "password"=>md5("1".$pwd)),
				array()
			);
	$loginBase->__set("execObj" , $obj);
	$result = $loginBase->__getAssocResult();
	if(empty($result)){
		header('Location: index.php?key=warabi');
		exit;
	}
	else{
		setcookie("warabi_admin" , true);
		header('Location: appuser.php');
	}
}
?>